﻿using System.IO;

namespace BookiFramework.Files
{
    public class Files
    {
        public string ReadText(Stream stream)
        {
            using (var reader = new StreamReader(stream))
            {
                stream.Position = 0;
                var text = reader.ReadToEnd();
                return text;
            }
        }

        public void WriteText(Stream stream, string input, bool append = false,bool closeStream=false)
        {            
            var writer = new StreamWriter(stream);            

            if (append)
                stream.Position = stream.Length-1;

            

            writer.WriteLine(input);
            writer.Flush();

            if(closeStream)
                writer.Dispose();
        }
    }
}
